package com.office.system.service.impl;

import com.office.system.service.MeetingMinutesService;
import org.springframework.stereotype.Service;
import java.util.*;
import com.office.system.domain.MeetingMinutes;
import com.office.system.mapper.MeetingMinutesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;

@Service
public class MeetingMinutesServiceImpl implements MeetingMinutesService {
    // 用于模拟存储会议纪要
    private final Map<Long, Map<String, Object>> store = new HashMap<>();
    private long idSeq = 1;

    @Autowired(required = false)
    private MeetingMinutesMapper meetingMinutesMapper;
    private final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public boolean saveMinutes(Map<String, Object> params) {
        try {
            MeetingMinutes minutes = new MeetingMinutes();
            minutes.setTopic((String) params.get("topic"));
            minutes.setParticipants((String) params.get("participants"));
            minutes.setSummary((String) params.get("summary"));
            // speakerViews为List<Map>，需转为JSON字符串
            Object speakerViews = params.get("speakerViews");
            if (speakerViews != null) {
                minutes.setSpeakerViews(objectMapper.writeValueAsString(speakerViews));
            }
            minutes.setRawText((String) params.get("rawText"));
            int rows = meetingMinutesMapper != null ? meetingMinutesMapper.insert(minutes) : 0;
            return rows > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean shareMinutes(Map<String, Object> params) {
        // 实际应实现分发逻辑，这里仅模拟
        return true;
    }

    @Override
    public List<Map<String, Object>> listMinutes(Map<String, Object> params) {
        return new ArrayList<>(store.values());
    }

    @Override
    public Map<String, Object> getMinutesDetail(Long id) {
        return store.getOrDefault(id, Collections.emptyMap());
    }
} 